<template>
 <div>
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogVisible" :fullscreen="true" :before-close="handleClose">
      <el-form  :inline="true" :rules="rules" ref="dataForm" 请选择 :model="temp" label-width="150px" >
        <el-form-item label="公司名称"  prop="company_id" class="form-item-full">
          <el-select style="width: 400px;" v-model="temp.company_id" placeholder="请选择" @change="companyChange" filterable >
            <el-option v-for="item in clientOptions" :key="item.id" :label="item.label" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属部门" prop="dept_id" class="form-item-full">
          <el-select style="width: 400px;" v-model="temp.dept_id" placeholder="请选择" >
            <el-option v-for="item in deptOptions" :key="item.id" :label="item.label" :value="item.id">
            </el-option>
          </el-select>
          <el-button icon="el-icon-plus" @click="handleAddDept">新增部门</el-button>
        </el-form-item>

        <el-form-item label="项目名称" prop="project_name" class="form-item">
          <el-input v-model="temp.project_name" style="width: 200px;" ></el-input>
        </el-form-item>
 
        <el-form-item label="人数" prop="recruitment_num" class="form-item">
          <el-input v-model="temp.recruitment_num" style="width: 200px;" ></el-input>
        </el-form-item>

        <el-form-item label="职能分类" prop="function_arr" class="form-item">
          <el-cascader v-model="temp.function_arr" 
                :options="function_cascader_options"
                :show-all-levels="false"
                :change-on-select="true"
                @change ="handleFunctionItemChange">
          </el-cascader> 
        </el-form-item>

        <el-form-item label="工作地点" prop="city" class="form-item">
          <treeselect 
                class="select-item" 
                :options="city_options"  
                  :show-count="true" 
                  placeholder="请选择" 
                  v-model="temp.city"/>
        </el-form-item>

        <el-form-item label="汇报对象" prop="leader" class="form-item">
          <el-input v-model="temp.leader" style="width: 200px;" ></el-input>
        </el-form-item>
        <el-form-item label="下属人数" prop="subordinates_num" class="form-item">
          <el-input v-model="temp.subordinates_num" style="width: 200px;" ></el-input>
        </el-form-item>
        <el-form-item label="税前年薪" required error="必填项" class="form-item-full">
          <el-col :span="11">
            <el-form-item prop="min_annual_salary">
              <el-input v-model="temp.min_annual_salary" style="width: 100px;" ></el-input>
            </el-form-item>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="11">
            <el-form-item prop="max_annual_salary">
              <el-input v-model="temp.max_annual_salary" style="width: 100px;" ></el-input>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="薪资构成" prop="salary_detail" class="form-item-full">
          <el-input type="textarea" :rows="6" v-model="temp.salary_detail" style="width: 600px;" ></el-input>
        </el-form-item>
        <el-form-item label="年龄要求" required error="必填项" class="form-item">
          <el-col :span="11">
            <el-form-item prop="min_age">
              <el-input v-model="temp.min_age" style="width: 80px;" ></el-input>
            </el-form-item>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="11">
            <el-form-item prop="max_age">
              <el-input v-model="temp.max_age" style="width: 80px;" ></el-input>
            </el-form-item>
          </el-col>
        </el-form-item>

        <el-form-item label="性别要求" prop="sex">
          <el-radio-group v-model="temp.sex">
            <el-radio label="0">不限</el-radio>
            <el-radio label="1">男</el-radio>
            <el-radio label="2">女</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="专业要求" prop="special_detail" class="form-item-full">
          <el-input v-model="temp.special_detail" style="width: 600px;" ></el-input>
        </el-form-item>
        <el-form-item label="工作年限" required error="必填项" class="form-item">
          <el-col :span="11">
            <el-form-item prop="min_year">
              <el-input v-model="temp.min_year" style="width: 80px;" ></el-input>
            </el-form-item>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="11">
            <el-form-item prop="max_year">
              <el-input v-model="temp.max_year" style="width: 80px;" ></el-input>
            </el-form-item>
          </el-col>
        </el-form-item>

        <el-form-item label="学历要求" class="form-item">
            <el-select v-model="temp.academic_qualification" filterable placeholder="请选择">
              <el-option
                v-for="item in education_backgroud_options"
                :key="item.id"
                :label="item.label"
                :value="item.id">
              </el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="是否统招全日制" class="form-item"  prop="is_unified">
          <el-radio-group v-model="temp.is_unified">
              <el-radio label="1">是</el-radio>
              <el-radio label="0">不限</el-radio>
          </el-radio-group>  
        </el-form-item>

        <el-form-item label="语言能力" prop="language_level_group" class="form-item">
            <treeselect
              class="select-item" 
              :multiple="true"
              :options="language_level_options"
              placeholder="请选择"
              v-model="temp.language_level_group"
              style="width:160px"
            />
        </el-form-item>

        <el-form-item label="所属行业"  prop="industry" class="form-item">
           <el-select v-model="temp.industry" placeholder="请选择" style="width: 280px;">
            <el-option
              v-for="item in industry_options"
              :key="item.id"
              :label="item.label"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      
        <el-form-item label="职位描述" prop="jd_detail" class="form-item-full">
            <el-input placeholder="岗位职责和能力需求" type="textarea" :rows="6" v-model="temp.jd_detail" style="width: 600px;" ></el-input>
        </el-form-item>

        <el-form-item label="项目级别" prop="project_priority" class="form-item-full">
          <el-select style="width: 400px;" v-model="temp.project_priority" placeholder="请选择">
            <el-option v-for="item in projectPriorityOptions " :key="item.key" :label="item.display_name" :value="item.key">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="招聘原因" prop="recruit_reason" class="form-item-full">
            <el-input placeholder="替代/增补" type="textarea" :rows="4" v-model="temp.recruit_reason" style="width: 600px;" ></el-input>
        </el-form-item>
        <el-form-item label="寻访方向" prop="search_direction" class="form-item-full">
            <el-input placeholder="目标公司" type="textarea" :rows="4" v-model="temp.search_direction" style="width: 600px;" ></el-input>
        </el-form-item>

        <el-form-item label="客户经理" prop="client_manager" class="form-item-full">
           <el-select class="filter-item"
              v-model="temp.client_manager"
              filterable
              placeholder="请选择">
            <el-option
              v-for="item in allUserOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="主要顾问" prop="manager_consultant" class="form-item-full">
           <el-select class="filter-item"
              v-model="temp.manager_consultant"
              filterable
              placeholder="请选择">
            <el-option
              v-for="item in allUserOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="其他" prop="" class="form-item-full">
           <el-button @click="handleAddC">添加</el-button>
           <el-button @click="handleBatchAddC">批量添加</el-button>
        </el-form-item>
         <div  v-for="(item,index) in this.temp.consultant_group" :key="index" >
            <el-form-item label="顾问" class="form-item-full">
              <el-select class="filter-item"
              v-model="temp.consultant_group[index]"
              filterable
              placeholder="请选择">
              <el-option
                v-for="item in allUserOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <i class="el-icon-delete" v-on:click="removeConsultant(index)"></i>
            </el-form-item>
          </div>

          <el-form-item v-if="dialogStatus=='submit' || dialogStatus=='create'" label="审核人" prop="approver_id" class="form-item-full">
           <el-select class="filter-item"
              v-model="temp.approver_id"
              filterable
              placeholder="请选择">
            <el-option
              v-for="item in allUserOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">{{$t('table.cancel')}}</el-button>
        <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">创建职位</el-button>
        <el-button v-if="dialogStatus=='create'" type="primary" @click="saveDraft">保存为草稿</el-button>
        <el-button v-if="dialogStatus=='submit'" type="primary" @click="apply">确定</el-button>
        <el-button v-if="dialogStatus=='update'" type="primary" @click="updateData">保存修改</el-button>
      </div>
    </el-dialog>
    <SelectUsersDialog :data="selectUsersData" :visible='selectUsersDialogVisible' @closeDialog="handleSelectUsersDialogVisible"></SelectUsersDialog>
    <OrgDialog :id='this.temp.company_id' :visible='orgDialogVisible' @closeDialog="handleCloseOrgDialog"> </OrgDialog>
 </div>
</template>

<script>

import OrgDialog from '@/views/company/components/orgDialog'
import SelectUsersDialog from './selectUsersDialog'
import API from '@/utils/backend_api'
import Static_Data from '@/data/index'
import _ from 'lodash'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
const simulateAsyncOperation = fn => {
  setTimeout(fn, 200)
}

const cityCascaderOptions = Static_Data.city.map((item) => {
  const item_children = []
  if (item.children && item.children.length > 0) {
    item.children.map(function(subitem) {
      item_children.push({ value: subitem.id, label: subitem.label })
    })
  }
  return { value: item.id, label: item.label, children: item_children }
})
const jobCascaderOptions = Static_Data.job.map((item) => {
  const item_children = []
  if (item.children && item.children.length > 0) {
    item.children.map(function(subitem) {
      item_children.push({ value: subitem.id, label: subitem.label })
    })
  }
  return { value: item.id, label: item.label, children: item_children }
})
export default {
  name: 'projectDialog',
  props: {
    id: {
      type: String,
      default: '' // 这样可以指定默认的值
    },
    visible: {
      type: Boolean,
      default: false // 这样可以指定默认的值
    },
    status: {
      type: String,
      default: 'create'
    }
  },
  components: { Treeselect, OrgDialog, SelectUsersDialog },
  data() {
    API.company.clients().then(response => {
      if (response.data && response.data.length > 0) {
        this.company_clients = response.data
        this.clientOptions = this.company_clients.map(item => {
          return { id: item.id, label: item.company_name }
        })
        console.log(this.clientOptions)
      }
    })

    return {
      rules: {
        company_id: [{ required: true, message: '必填项', trigger: 'change' }],
        project_name: [{ required: true, message: '必填项', trigger: 'change' }],
        function_arr: [{ required: true, message: '必填项', trigger: 'change' }],
        city: [{ required: true, message: '必填项', trigger: 'change' }],
        industry: [{ required: true, message: '必填项', trigger: 'change' }],
        client_manager: [{ required: true, message: '必填项', trigger: 'change' }],
        manager_consultant: [{ required: true, message: '必填项', trigger: 'change' }]
      },
      selectUsersData: [],
      selectUsersDialogVisible: false,
      allUserOptions: this.$store.getters.usersList.map(item => ({ value: item.id, label: item.username + '(' + item.uid + ')', username: item.username })),
      orgDialogVisible: false,
      company_clients: [],
      clientOptions: [],
      company_org: { id: '' },
      deptOptions: [],
      function_cascader_options: jobCascaderOptions,
      city_options: Static_Data.city,
      city_cascader_options: cityCascaderOptions,
      industry_options: Static_Data.industry,
      marriageOptions: Static_Data.marriage,
      genderOptions: Static_Data.gender,
      projectStatusOptions: Static_Data.project_status,
      projectPriorityOptions: Static_Data.project_priority,
      language_level_options: Static_Data.language_level,
      education_backgroud_options: Static_Data.education_backgroud,
      temp: {
        sex: '0',
        is_unified: '0',
        dept_id: '',
        company_id: '',
        consultant_group: [],
        function_arr: []
      },
      dialogStatus: '',
      dialogVisible: false,
      textMap: {
        update: '编辑项目',
        submit: '提交审核',
        create: '新增项目'
      }
    }
  },
  filters: {
  },
  created() {
  },
  watch: {
    id: function(val, oldVal) {
      if (val !== '' && (this.status === 'update' || this.status === 'submit')) {
        API.project.get(val).then(response => {
          this.temp = response.data
          if (this.temp.company_id) {
            API.company_org.get(this.temp.company_id).then(response => {
              this.company_org = response.data
              if (this.company_org && this.company_org.dept_org) {
                const deptData = JSON.parse(this.company_org.dept_org)
                const parseOrg = function(item) {
                  if (item.children && item.children.length > 0) {
                    const item_arr = _.flatMapDeep(item.children, parseOrg)
                    item_arr.push({ id: item.id, label: item.label })
                    return item_arr
                  }
                  return { id: item.id, label: item.label }
                }
                this.deptOptions = _.flatMapDeep(deptData, parseOrg)
                if (this.temp.dept_id) {
                  this.temp.dept_id = this.temp.dept_id
                }
              }
            })
          }
          if (this.temp.consultant_group && this.temp.consultant_group.length > 0) {
            this.temp.consultant_group = this.temp.consultant_group.map(item => item.user_id)
          } else {
            this.temp.consultant_group = []
          }

          if (this.temp.language_level_group) {
            this.temp.language_level_group = JSON.parse(this.temp.language_level_group)
          }
          if (this.temp.function) {
            if (this.temp.function.length === 4) {
              this.temp.function_arr = [this.temp.function]
            }
            if (this.temp.function.length === 8) {
              this.temp.function_arr = [this.temp.function.substr(0, 4), this.temp.function]
            }
          }
        })
      }
    },
    visible: function(val, oldVal) {
      console.log('当前值为：' + val, '旧值为：' + oldVal)
      if (this.status === 'update' || this.id !== '') {
        // API.candidate.get(this.id)
      } else {
        this.resetData()
      }
      if (val) {
        setTimeout(() => { this.dialogVisible = val }, 1000)
      } else {
        this.dialogVisible = val
      }
    },
    status: function(val, oldVal) {
      console.log('当前值为：' + val, '旧值为：' + oldVal)
      this.dialogStatus = val
    }
  },
  computed: {
  },
  methods: {
    getDeptNameById(id) {
      let dept_name = ''
      this.deptOptions.map(item => {
        if (item.id === id) {
          dept_name = item.label
        }
      })
      return dept_name
    },
    getCompanyNameById(id) {
      let company_name = ''
      this.clientOptions.map(item => {
        if (item.id === id) {
          company_name = item.label
        }
      })
      return company_name
    },
    getUsernameById(id) {
      let username = ''
      this.allUserOptions.map(item => {
        if (item.value === id) {
          username = item.username
        }
      })
      return username
    },
    removeConsultant(index) {
      this.temp.consultant_group.splice(index, 1)
    },
    handleAddC() {
      this.temp.consultant_group.push('')
    },
    handleBatchAddC() {
      this.selectUsersData = []
      this.temp.consultant_group.map(item => {
        if (this.selectUsersData.indexOf(item) < 0) {
          this.selectUsersData.push(item)
        }
      })
      this.selectUsersDialogVisible = true
    },
    handleSelectUsersDialogVisible(val) {
      if (val && val.type === 'success' && val.data) {
        this.temp.consultant_group = []
        val.data.map(item => {
          if (this.temp.consultant_group.indexOf(item) < 0) {
            this.temp.consultant_group.push(item)
          }
        })
      }
      this.selectUsersDialogVisible = false
    },
    parseOrg(item) {
      if (item.children && item.children.length > 0) {
        const item_arr = _.flatMapDeep(item.children, this.parseOrg)
        item_arr.push({ id: item.id, label: item.label })
        return item_arr
      }
      return { id: item.id, label: item.label }
    },
    handleAddDept() {
      if (this.temp.company_id && this.temp.company_id !== '') {
        this.orgDialogVisible = true
      } else {
        this.$message({
          message: '请选择公司',
          type: 'warning'
        })
      }
    },
    handleCloseOrgDialog(val) {
      if (val && val.type === 'cancel' && val.data) {
        this.orgDialogVisible = false
      }
      if (val && val.type === 'success' && val.data) {
        this.deptOptions = _.flatMapDeep(val.data, this.parseOrg)
        this.orgDialogVisible = false
      }
    },
    companyChange(company) {
      API.company_org.get(company).then(response => {
        this.company_org = response.data
        if (this.company_org && this.company_org.dept_org) {
          const deptData = JSON.parse(this.company_org.dept_org)
          const parseOrg = function(item) {
            if (item.children && item.children.length > 0) {
              const item_arr = _.flatMapDeep(item.children, parseOrg)
              item_arr.push({ id: item.id, label: item.label })
              return item_arr
            }
            return { id: item.id, label: item.label }
          }
          this.deptOptions = _.flatMapDeep(deptData, parseOrg)
          this.temp.dept_id = ''
        }
      })
    },
    handleFunctionItemChange(arr) {
      if (arr && arr.length > 0) {
        this.temp.function = arr[arr.length - 1]
      }
    },
    handleCityItemChange(arr) {
      if (arr && arr.length > 0) {
        this.temp.city = arr[arr.length - 1]
      }
    },
    saveDraft() {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return
        }
        const add_data = {
          project_name: this.temp.project_name || '',
          company_id: this.temp.company_id || '',
          company_name: this.getCompanyNameById(this.temp.company_id) || '',
          dept_id: this.temp.dept_id || '',
          dept_name: this.getDeptNameById(this.temp.dept_id) || '',
          leader: this.temp.leader || '',
          subordinates_num: this.temp.subordinates_num || '',
          is_unified: this.temp.is_unified,
          sex: this.temp.sex,
          special_detail: this.temp.special_detail || '',
          min_annual_salary: this.temp.min_annual_salary || '',
          max_annual_salary: this.temp.max_annual_salary || '',
          salary_detail: this.temp.salary_detail || '',
          jd_detail: this.temp.jd_detail || '',
          language_level_group: this.temp.language_level_group || [],
          academic_qualification: this.temp.academic_qualification || '',
          min_age: this.temp.min_age || '',
          max_age: this.temp.max_age || '',
          min_year: this.temp.min_year || '',
          max_year: this.temp.max_year || '',
          search_direction: this.temp.search_direction || '',
          recruit_reason: this.temp.recruit_reason || '',
          client_manager: this.temp.client_manager || '',
          approver_id: this.temp.approver_id || '',
          approver_name: this.getUsernameById(this.temp.approver_id) || '',
          remark: this.temp.remark || '',
          city: this.temp.city,
          manager_consultant: this.temp.manager_consultant,
          project_priority: this.temp.project_priority,
          recruitment_num: this.temp.recruitment_num || '',
          industry: this.temp.industry,
          function: this.temp.function,
          newest_update_time: '' + Date.parse(new Date()),
          consultant_group: this.temp.consultant_group
        }
        console.log(add_data)
        API.project.add('Applying', add_data).then((response) => {
          console.log(response)
          this.resetData()
          this.$emit('closeDialog', { type: 'create_success', data: response.data })
          this.$notify({
            title: '成功',
            message: '创建成功',
            type: 'success',
            duration: 2000
          })
        })
      })
    },
    apply() {
      this.$refs['dataForm'].validate((valid) => {
        const submit_data = {
          id: this.temp.id,
          project_name: this.temp.project_name || '',
          company_id: this.temp.company_id || '',
          company_name: this.getCompanyNameById(this.temp.company_id) || '',
          dept_id: this.temp.dept_id || '',
          dept_name: this.getDeptNameById(this.temp.dept_id) || '',
          leader: this.temp.leader || '',
          subordinates_num: this.temp.subordinates_num || '',
          is_unified: this.temp.is_unified,
          sex: this.temp.sex,
          special_detail: this.temp.special_detail || '',
          min_annual_salary: this.temp.min_annual_salary || '',
          max_annual_salary: this.temp.max_annual_salary || '',
          salary_detail: this.temp.salary_detail || '',
          jd_detail: this.temp.jd_detail || '',
          language_level_group: this.temp.language_level_group || [],
          academic_qualification: this.temp.academic_qualification || '',
          min_age: this.temp.min_age || '',
          max_age: this.temp.max_age || '',
          min_year: this.temp.min_year || '',
          max_year: this.temp.max_year || '',
          search_direction: this.temp.search_direction || '',
          recruit_reason: this.temp.recruit_reason || '',
          client_manager: this.temp.client_manager || '',
          approver_id: this.temp.approver_id || '',
          approver_name: this.getUsernameById(this.temp.approver_id) || '',
          remark: this.temp.remark || '',
          city: this.temp.city,
          manager_consultant: this.temp.manager_consultant,
          project_priority: this.temp.project_priority,
          recruitment_num: this.temp.recruitment_num || '',
          industry: this.temp.industry,
          function: this.temp.function,
          newest_update_time: '' + Date.parse(new Date()),
          consultant_group: this.temp.consultant_group
        }
        console.log(submit_data)
        API.project.apply(this.temp.id, submit_data).then((response) => {
          console.log(response)
          this.resetData()
          this.$emit('closeDialog', { type: 'submit_success', data: response.data })
          this.$notify({
            title: '成功',
            message: '提交成功',
            type: 'success',
            duration: 2000
          })
        })
      })
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return
        }
        const add_data = {
          project_name: this.temp.project_name || '',
          company_id: this.temp.company_id || '',
          company_name: this.getCompanyNameById(this.temp.company_id) || '',
          dept_id: this.temp.dept_id || '',
          dept_name: this.getDeptNameById(this.temp.dept_id) || '',
          leader: this.temp.leader || '',
          subordinates_num: this.temp.subordinates_num || '',
          is_unified: this.temp.is_unified,
          sex: this.temp.sex,
          special_detail: this.temp.special_detail || '',
          min_annual_salary: this.temp.min_annual_salary || '',
          max_annual_salary: this.temp.max_annual_salary || '',
          salary_detail: this.temp.salary_detail || '',
          jd_detail: this.temp.jd_detail || '',
          language_level_group: this.temp.language_level_group || [],
          academic_qualification: this.temp.academic_qualification || '',
          min_age: this.temp.min_age || '',
          max_age: this.temp.max_age || '',
          min_year: this.temp.min_year || '',
          max_year: this.temp.max_year || '',
          search_direction: this.temp.search_direction || '',
          recruit_reason: this.temp.recruit_reason || '',
          client_manager: this.temp.client_manager || '',
          approver_id: this.temp.approver_id || '',
          approver_name: this.getUsernameById(this.temp.approver_id) || '',
          remark: this.temp.remark || '',
          city: this.temp.city,
          manager_consultant: this.temp.manager_consultant,
          project_priority: this.temp.project_priority,
          recruitment_num: this.temp.recruitment_num || '',
          industry: this.temp.industry,
          function: this.temp.function,
          newest_update_time: '' + Date.parse(new Date()),
          consultant_group: this.temp.consultant_group
        }
        console.log(add_data)
        API.project.add('Wait_approve', add_data).then((response) => {
          console.log(response)
          this.resetData()
          this.$emit('closeDialog', { type: 'create_success', data: response.data })
          this.$notify({
            title: '成功',
            message: '创建成功',
            type: 'success',
            duration: 2000
          })
        })
      })
    },
    updateData(data) {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return
        }
        const update_data = {
          id: this.temp.id,
          project_name: this.temp.project_name || '',
          company_id: this.temp.company_id || '',
          company_name: this.getCompanyNameById(this.temp.company_id) || '',
          dept_id: this.temp.dept_id || '',
          dept_name: this.getDeptNameById(this.temp.dept_id) || '',
          leader: this.temp.leader || '',
          subordinates_num: this.temp.subordinates_num || '',
          is_unified: this.temp.is_unified,
          sex: this.temp.sex,
          special_detail: this.temp.special_detail || '',
          min_annual_salary: this.temp.min_annual_salary || '',
          max_annual_salary: this.temp.max_annual_salary || '',
          salary_detail: this.temp.salary_detail || '',
          jd_detail: this.temp.jd_detail || '',
          language_level_group: this.temp.language_level_group || [],
          academic_qualification: this.temp.academic_qualification || '',
          min_age: this.temp.min_age || '',
          max_age: this.temp.max_age || '',
          min_year: this.temp.min_year || '',
          max_year: this.temp.max_year || '',
          search_direction: this.temp.search_direction || '',
          recruit_reason: this.temp.recruit_reason || '',
          client_manager: this.temp.client_manager || '',
          remark: this.temp.remark || '',
          city: this.temp.city,
          manager_consultant: this.temp.manager_consultant,
          project_priority: this.temp.project_priority,
          recruitment_num: this.temp.recruitment_num || '',
          industry: this.temp.industry,
          function: this.temp.function,
          newest_update_time: '' + Date.parse(new Date()),
          consultant_group: this.temp.consultant_group
        }
        API.project.update(update_data).then((response) => {
          console.log(response)
          this.resetData()
          this.$emit('closeDialog', { type: 'update_success', data: response.data })
          this.$notify({
            title: '成功',
            message: '更新成功',
            type: 'success',
            duration: 2000
          })
        })
      })
    },
    handleCancel() {
      this.$emit('closeDialog', { type: 'cancel', data: {}})
      this.resetData()
    },
    handleClose(done) {
      this.$emit('closeDialog', { type: 'cancel', data: {}})
      this.resetData()
    },
    resetData() {
      this.temp = {
        sex: '0',
        is_unified: '0',
        dept_id: '',
        company_id: '',
        consultant_group: [],
        function_arr: []
      }
    },
    loadChildrenOptions({ action, parentNode, callback }) {
      if (action === LOAD_CHILDREN_OPTIONS) {
        switch (parentNode.id) {
          default: /* empty */
            simulateAsyncOperation(() => {
              callback()
            })
        }
      }
    }
  }
}
</script>
<style scoped>
  .form-row {
    display: block;
  }
  .form-item {
    width: 40%
  }

  .form-item-full {
    width: 100%
  }
  .form-content{
    overflow:hidden;
    border: 1px solid #ddd;
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: 0;
    border-top-left-radius: 0;
    box-sizing: content-box;
    width: 80%;
    margin-left:5%;
  }
  .form-header {
    height: 40px;
    line-height: 15px;
    color: #676a6c;
    background-color: #F9F9F9;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    border: 1px solid #ddd;
  }
  .form-table-border{
    margin: 1px 1px 1px 1px;
    border: 1px solid #ddd;
  }
  .form-header-button {
    float: right;
    margin: 0.3em 1em 0;
  } 
  .form-header-title{
    float: left;
    margin: 1.1em 1em 0.2em;
  }
  .select-item {
    display: inline-block;
    vertical-align: middle;
    width: 200px;
  }

</style>

